home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 445_01 / cdntmr11 / bt.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-15  |  4.0 KB  |  183 lines

  1. //Header file
  2. // M\Cooper, 3425 Chestnut Ridge Rd., Grantsville, MD 21536-9801
  3. // Email: thegrendel@aol.com
  4.  
  5. /***************************************************************************/
  6.  
  7. extern "C" two_tone(),
  8.        blatt(),
  9.     beep1();
  10.  
  11. #define PLAY 1
  12. #define GAME_OVER 1
  13. #define QUIT 2    
  14. #define ESC 27
  15. #define MAXLEN 4
  16. #define BUFSIZE 12
  17. #define BLK_TIME 226
  18. #define NAME_POS 190
  19. #define Y_TIMEPOS 300
  20. #define POS_OFFSET 158
  21. #define POS1_OFFSET 130
  22. #define COLORS 15
  23. #define PATTERNS 11
  24. #define RADIUS 50
  25. #define X_C 315
  26. #define Y_C 225
  27. #define MOVES_X 316
  28. #define MOVES_Y 440
  29. #define BKGRND_COLOR WHITE
  30.  
  31. typedef enum { FALSE, TRUE } BOOLEAN;
  32. enum FLAG { OFF, ON };
  33. enum Player { WHITE_, BLACK_ };
  34.  
  35. char *player[] = { "White", "Black" },
  36.      esc_msg[] =   "Press ESC to exit",
  37.      title_msg[] = "Countdown Timer";
  38.  
  39. void graphics_setup( int ),
  40.      exit__(),
  41.      erase();
  42.  
  43.  
  44.  
  45. class CountdownTimer
  46.    {
  47.    protected:
  48.       int hours,
  49.       minutes,
  50.       moves,
  51.       warning,
  52.       text_color;
  53.       char line_clear [ BUFSIZE ];
  54.       Player p;
  55.       FLAG running_flag,
  56.        visual_ticking_flag,
  57.        time_warning_flag;
  58.       time_t seconds,
  59.          total_seconds,
  60.          total_seconds_mem,
  61.          start_t,
  62.          end_t,
  63.          startn_t,
  64.          interval_t,
  65.          running_t;
  66.    public:
  67.       CountdownTimer()
  68.       {
  69.        hours = 0; minutes = 3; moves = 0; seconds = 0L;
  70.        total_seconds = total_seconds_mem = (long)hours * 3600L + (long)minutes * 60L;
  71.       }
  72.       CountdownTimer( int hrs, int min, time_t sec, Player pl )
  73.       {
  74.       hours = hrs; minutes = min; seconds = sec; moves = 0;
  75.       total_seconds = (long)hours * 3600L + (long)minutes * 60L + seconds;
  76.       total_seconds_mem = total_seconds;
  77.       p = pl;
  78.       }
  79.       CountdownTimer( int min, time_t sec, Player pl )
  80.       { 
  81.       sec += (long)min * 60L;
  82.       total_seconds = total_seconds_mem = sec; 
  83.       hours = sec / 3600;
  84.       minutes = ( sec % 3600 ) / 60;
  85.       seconds = sec % 60;
  86.       moves = 0;
  87.       p = pl;
  88.       }
  89.       CountdownTimer( int hrs, int min, Player pl )
  90.      {
  91.      hours = hrs; minutes = min; seconds = 0L; moves = 0;
  92.      total_seconds = total_seconds_mem = (long)hours * 3600L + (long)minutes * 60L;
  93.      p = pl;
  94.      }
  95.       CountdownTimer( time_t sec, Player pl )
  96.       {
  97.       total_seconds = total_seconds_mem = sec;
  98.       convert( sec );
  99.       p = pl;
  100.       moves = 0;
  101.       }
  102.  
  103.       CountdownTimer( int min )
  104.      {
  105.      hours = min / 60;
  106.      minutes = min % 60;
  107.      seconds = 0L; moves = 0;
  108.      total_seconds = total_seconds_mem = (long)min * 60L;
  109.      }
  110.  
  111.       void convert( time_t sec )
  112.       { 
  113.       hours = sec / 3600;
  114.       sec %= 3600;
  115.       minutes = sec / 60;
  116.       seconds = sec % 60;
  117.       }
  118.  
  119.       void display_time()
  120.       {
  121.       char dbuff [ BUFSIZE ];
  122.  
  123.          sprintf( dbuff,  "%02d:%02d:%02ld", hours, minutes, seconds );
  124.  
  125.          erase_numbers();  // Wipe off old time.
  126.          
  127.          setcolor( text_color );
  128.          outtextxy( BLK_TIME, Y_TIMEPOS, dbuff );
  129.          sprintf( line_clear, dbuff );
  130.       }
  131.  
  132.       BOOLEAN timeout()
  133.      {
  134.      if( !hours )
  135.         if( !minutes )
  136.            if( !seconds )
  137.           {
  138.           two_tone();
  139.           return ( TRUE );
  140.           }
  141.      return ( FALSE );
  142.      }
  143.  
  144. void exit_()
  145.    char ch;
  146.  
  147.       setcolor( BKGRND_COLOR );
  148.       settextstyle( TRIPLEX_FONT, HORIZ_DIR, 1 );
  149.       outtextxy( NAME_POS, 100, "Press a key to stop timer" );
  150.       setcolor( CYAN );
  151.       outtextxy( NAME_POS, 100, "Press a key to reset timer" );
  152.       ch = getch();
  153.       if( ch == ESC )
  154.      exit__(); // Quit.
  155.  
  156.       setcolor( BKGRND_COLOR );
  157.       outtextxy( NAME_POS, 100, "Press a key to reset timer" );
  158.       setcolor( BLUE );
  159.       outtextxy( NAME_POS, 100, "Press a key to stop timer" );
  160.  
  161.       return;
  162. }
  163.  
  164.       void initialize_clock()
  165.       {
  166.       running_flag = OFF;  //Clock is running.
  167.       running_t = 0;
  168.       start_t = time( NULL );
  169.       }
  170.  
  171.       void clock_on(),
  172.        erase_numbers(),
  173.        display_moves(),
  174.        reset_timer(),
  175.        erase();
  176.  
  177.       friend void play();
  178.  
  179.     
  180.     }; //end class defn.
  181.  
  182.